package other.xsy.pms.utils;

import com.rkhd.platform.sdk.data.model.Opportunity;
import com.rkhd.platform.sdk.data.model.QuoteLine;
import com.rkhd.platform.sdk.exception.ApiEntityServiceException;

import java.util.Arrays;
import java.util.List;

public class TestDemo01 {
    private static HCXObjectService hcxObjectService = new HCXObjectService();

    public static void main(String[] args) throws ApiEntityServiceException {
//        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,12,13,14);
//        for (Integer integer : list) {
//            String sql = "select id,accountName,customItem206__c from account where customItem206__c is not null and SyncStatus__c = 1";
//            List<Account> query = (List<Account>) hcxObjectService.query(sql);
//            for (Account account : query) {
//                account.setAccountNo__c(account.getCustomItem206__c());
//                account.setSyncStatus__c(2);
//            }
//            hcxObjectService.batchUpdate(query);
//        }

        test02();
    }

    private static void test01() throws ApiEntityServiceException {
        String sql = "select id,name from quoteLine order by createdAt desc";


        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,12,13,14,15,16,17,18,19,20);
        for (Integer integer : list) {
            List<QuoteLine> query = (List<QuoteLine>)hcxObjectService.query(sql);
            System.out.println(hcxObjectService.batchDelete(query));
        }

    }

    private static void test02() throws ApiEntityServiceException {
        String sql = "select id,businessOpportunityNumber__c,opportunityName from opportunity where businessOpportunityNumber__c is not null and SyncStatus__c = 1";
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,12,13,14,15,16,17,18,19,20);
        for (Integer integer : list) {
            List<Opportunity> query = (List<Opportunity>)hcxObjectService.query(sql);
            for (Opportunity opportunity : query) {
                opportunity.setProjectCode__c(opportunity.getBusinessOpportunityNumber__c());
                opportunity.setSyncStatus__c(2);
            }
            try {
                hcxObjectService.batchUpdate(query);
            }catch (Exception e) {
                System.out.println("同步超时。");
            }
        }
    }
}
